<?php


namespace Modules\Admin\Http\Controllers\Authorization\Permission;


use Modules\Common\Models\AdminPermission;
use Modules\Common\Util\Api;

class Sort
{
    /**
     * @Route(path=/api/admin/authorization/permision/sort method=post)
     */
    public function index()
    {
        Api::validate( ['permission_id' => 'integer', 'up_down' => 'in:1,-1,99999,-99999']);
        $permission = AdminPermission::find(request('permission_id'));

        switch (request('up_down')) {
            case 1:
                $permission->moveOrderUp();
                break;
            case -1:
                $permission->moveOrderDown();
                break;
            case 99999:
                $permission->moveToStart();
                break;
            case -99999:
                $permission->moveToEnd();
                break;
        }
        return Api::success();
    }


}
